<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use App\Http\Middleware\WordFilteringMiddleware;
use App\Http\Model\Room;
use App\Http\Model\User;

class HandelContentWordFilter extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'handelContentWordFilter';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '处理内容关键词筛选';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $result = Redis::HGETALL("HANDEL:CONTENT:WORD:LIST");
        foreach ($result as $key => $value) {
            $value = json_decode($value, true);
            if ($value['results']) {
                foreach ($value['results'] as $vkey => $vvalue) {
                    if ($vvalue[0] && isset($vvalue[0]['results'])) {
                        foreach ($vvalue[0]['results'] as $rkey => $rvalue) {
                            if(in_array($rvalue['label'], ["politics", "terrorism", "porn"])){
                                var_dump($value['handle']['data']['user_id']);
                                Redis::HSET("HANDEL:CONTENT:WORD:LIST:FILTER", $value['handle']['data']['user_id'], json_encode($value));
                            }
                        }
                    }
                }
            }
        }
    }
}
